package com.mryan.ps_common.handle;

import com.mryan.ps_common.entity.PSResponse;
import com.mryan.ps_common.utils.PSUtils;
import org.springframework.http.MediaType;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @BelongsProject: ps_cloud
 * @BelongsPackage: com.mryan.ps_common.handle
 * @Author: Yan
 * @CreateTime: 2021-04-25 21:13
 * @Description: 403异常
 */
public class PSAccessDeniedHandler implements AccessDeniedHandler {

	@Override
	public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
	                   AccessDeniedException e) throws IOException, ServletException {
		PSResponse psResponse = new PSResponse();
		PSUtils.makeResponse(httpServletResponse, MediaType.APPLICATION_JSON_UTF8_VALUE,
				HttpServletResponse.SC_FORBIDDEN, psResponse.message("没有权限访问"));
	}
}
